package cn.qiyu5522.tk_ems.controller.admin;


import cn.hutool.core.date.LocalDateTimeUtil;
import cn.qiyu5522.tk_ems.entity.ResumeDeliveryRecord;
import cn.qiyu5522.tk_ems.entity.dto.QueryParamDTO;
import cn.qiyu5522.tk_ems.entity.dto.ResumeDeliveryRecordDTO;
import cn.qiyu5522.tk_ems.myanotation.WebLog;
import cn.qiyu5522.tk_ems.result.R;
import cn.qiyu5522.tk_ems.service.ResumeDeliveryRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 学生简历投递状态投递记录表 前端控制器
 * </p>
 *
 * @author Tonkey
 * @since 2023-03-01
 */
@Api(tags = "简历投递状态投递状态")
@RestController
@RequestMapping("admin/resumeDelivery")
public class ResumeDeliveryRecordController {
    @Resource
    private ResumeDeliveryRecordService resumeDeliveryRecordService;

    @WebLog(description = "分页条件查询简历投递状态列表")
    @ApiOperation("简历投递状态列表查询")
    @ApiImplicitParam(name = "queryParamDTO", value = "条件查询对象", required = true,dataType ="QueryParamDTO" ,dataTypeClass = QueryParamDTO.class)
    @PostMapping("/query")
    public R query(@Validated(QueryParamDTO.Query.class) @RequestBody QueryParamDTO<ResumeDeliveryRecordDTO> queryParamDTO) {
        return resumeDeliveryRecordService.queryResumeDeliveryRecordByPageCondition(queryParamDTO);
    }
    @WebLog(description = "简历投递状态新增--批量")
    @ApiOperation("简历投递状态新增")
    @ApiImplicitParam(name = "resumeDeliveryRecordDTOs", value = "简历投递状态新增", required = true,dataType = "List",dataTypeClass = List.class)
    @PostMapping("/add")
    public R add(@Validated(ResumeDeliveryRecord.Insert.class) @RequestBody List<ResumeDeliveryRecordDTO> resumeDeliveryRecordDTOs) {

        return resumeDeliveryRecordService.saveMore(resumeDeliveryRecordDTOs);
    }
    @WebLog(description = "简历投递状态编辑")
    @ApiOperation("简历投递状态编辑")
    @ApiImplicitParam(name = "resumeDeliveryRecordDTO", value = "简历投递状态实体类对象", required = true, defaultValue = "{}", dataTypeClass = ResumeDeliveryRecordDTO.class)
    @PutMapping("/edit")
    public R edit(@Validated(ResumeDeliveryRecord.Update.class) @RequestBody ResumeDeliveryRecordDTO resumeDeliveryRecordDTO) {
        ResumeDeliveryRecord resumeDeliveryRecord = new ResumeDeliveryRecord();
        BeanUtils.copyProperties(resumeDeliveryRecordDTO,resumeDeliveryRecord);
        if(resumeDeliveryRecord.getState()==1){
            resumeDeliveryRecord.setViewTime(LocalDateTimeUtil.now());
        }
        boolean b = resumeDeliveryRecordService.updateById(resumeDeliveryRecord);
        return b ? R.ok().message("编辑成功") : R.error().message("编辑失败");
    }
    @WebLog(description = "简历投递状态删除")
    @ApiOperation("简历投递状态删除")
    @ApiImplicitParam(name = "ids", value = "简历投递状态编号集合", required = true, dataTypeClass = List.class)
    @PostMapping("/remove")
    public R remove(@RequestBody List<Long> ids) {
        boolean b = resumeDeliveryRecordService.removeByIds(ids);
        return b ? R.ok().message("删除成功!"):R.error().message("删除失败");
    }

}
